<template>
  <a-modal width="40%" v-model="isModel" :footer="null" :forceRender="true">
    <template slot="title">
      复制按钮:
      <a-select
        @change="configChange"
        placeholder="请选择流程配置"
        style="width: 80%"
        showSearch
        :filter-option="filterOption"
      >
        <a-select-option v-for="item in configList" :key="item.id" :value="item.id"> {{ item.name_ }} </a-select-option>
      </a-select>
    </template>
    <!-- 选择环节 -->
    选择环节:
    <a-select
      v-model="stepidValue"
      placeholder="请选择流程环节"
      style="width: 80%"
      showSearch
      :filter-option="filterOption"
    >
      <a-select-option v-for="item in stepList" :key="item.id" :value="item.id"> {{ item.name }} </a-select-option>
    </a-select>

    <div style="text-align: center; margin-top: 50px">
      <a-button :disabled="stepidValue == undefined" type="primary" @click="stepSave"> 确定 </a-button>
    </div>
  </a-modal>
</template>
<script>
import { queryAct_dsn_form_defineList } from '@/api/workflow/act_dsn_form_define.js'
import { listAssociatedProcess } from '@/api/workflow/act_dsn_form_step.js'
import { queryAct_dsn_form_stepbtnList } from '@/api/workflow/act_dsn_form_stepbtn.js'
export default {
  props: {
    stepid: {
      type: String,
      require: true,
    },
    formid: { type: String, require: true },
  },
  data() {
    return {
      stepidValue: undefined,
      isModel: false,
      configList: [], // 事项列表
      stepList: [], // 环节列表
    }
  },
  created() {},
  methods: {
    stepSave() {
      // console.log('stepidValue', this.stepidValue)
      let body = {}
      for (let v of this.stepList) {
        if (v.id == this.stepidValue) {
          body = v
          break
        }
      }
      queryAct_dsn_form_stepbtnList({
        f_formid_: body.formid_,
        f_stepid_: this.stepidValue,
        pageSize: 999999
      }).then((res) => {
        if (res.code == 0) {
          console.log('按钮配置', res)
          if (res.code == 0 && res.data?.records) {
            this.$emit('f_copySave', res.data.records)
            this.isModel = false
          }
        }
      })
    },
    f_init() {
      this.stepidValue = undefined
      this.isModel = true
      queryAct_dsn_form_defineList({ f_version_: 0, pageSize: 999999 }).then((res) => {
        // console.log('零号版本流程', res)
        if (res.code == 0) {
          this.configList = res.data?.records || []
        }
      })
    },
    configChange(value) {
      console.log('value', value)
      listAssociatedProcess({ f_formid_: value, pageSize: 999999 }).then((res) => {
        if (res.code == 0) {
          this.stepList = res.data?.records || []
          // console.log('已配置环节', res)
        }
      })
    },
    // 下拉框搜索
    filterOption(input, option) {
      return option.componentOptions.children[0].text.indexOf(input) >= 0
    },
  },
}
</script>

<style lang="scss" scoped>
</style>
